package com.chahua.organized.handler;

import com.chahua.organized.common.BaseResponseCode;
import com.chahua.organized.common.DataResult;
import com.chahua.organized.exception.DepartmentException;
import com.chahua.organized.exception.DepartmentMemberException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author chahua
 * @date 2022/4/9 21:10
 **/
@RestControllerAdvice
@Slf4j
public class MyExceptionHandler {

    /**
     * 部门异常处理
     * @param e  DepartmentException
     * @return ApiResponse
     */
    @ExceptionHandler(DepartmentException.class)
    public DataResult handleDepartmentException(DepartmentException e){
        return new DataResult(BaseResponseCode.FAIL.getCode(),e.getMessage());
    }

    @ExceptionHandler(DepartmentMemberException.class)
    public DataResult handleDepartmentException(DepartmentMemberException e){
        return DataResult.getResult(BaseResponseCode.FAIL.getCode(),e.getMessage());
    }

}
